package com.intelligent.bot.utils.sys;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.intelligent.bot.base.exception.E;
import com.intelligent.bot.constant.CommonConst;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TxMapUtil {



    public static JSONObject geocoder(String location){
        String url = "https://apis.map.qq.com/ws/geocoder/v1/?location=";
        url = url + location + "&get_poi=0" + "&key=" + CommonConst.TX_MAP_KEY;
        String body = HttpUtil.createGet(url).execute().body();
        JSONObject jsonObject = JSONObject.parseObject(body);
        if(jsonObject.getInteger("status") == 0){
            return jsonObject.getJSONObject("result").getJSONObject("address_component");
        }else {
            throw new E("获取地理位置失败");
        }
    }

    public static void main(String[] args) {
        JSONObject geocoder = geocoder("40.104950,124.360410");
        System.out.println(geocoder.getString("city"));
    }

}
